﻿/* =========================================================
 * treeList.js v1.0.0
 * =========================================================
 *修改记录：
 *
 *
 *
 *
 *
 * ========================================================= */

var treeHeight = document.documentElement.clientHeight;
var treeWidth = 280;
(function($, window, document, undefined) {
	/* global jQuery, console */
	'use strict';

	var pluginName = 'treeview';
	var Tree = function(element, options) {
		this.$element = $(element);
		this._element = element;
		this._elementId = this._element.id;
		$("." + this._element.parentElement.className).css("height", treeHeight);

		this.treeData = [];
		this.nodes = [];
		this.mulitCheck = [];
		this.selectedNode = {};
		this.template = "";
		this.checked = [];
		this.checkStationType = [];
		this.radioStationType = "";
		this.firstCheckAll = true;
		this._loadTemplate(options);
		this.checkBoxCookies = [];
		this.firstLoad = true;
		this.checkOneStation = false;
	};

	Tree.defaults = {
		dataUrl : "", // 可自定义数据获取地址
		showOtherInfo : false, // 显示其他信息，如地址，电话
		showAlarm : false, // 是否显示告警列表树
		checkAlarm : false, // 是否显示告警选择
		showMenu : false, // 是否是菜单树
		showMenuAll : true, // 菜单树全部展开 flase为展开第一个
		showArea : false, // 是否显示区域
		showOrg : false, // 是否显示企业
		showStation : true, // 是否显示站点
		showRights : false, // 是否根据权限过滤数据
		mulitCheck : false, // 是否多选
		checkBoxCookied : false, // 是否保留记录到cookie
		showPointType: false,
		stationTypeMulit : true, // 站点类型是否多选
		stationTypeCheckOne : false, // 站点类型是否多选
		accordion : true, // 是否展开动画效果
		closedSign : '/'+bfsprojectName+'/component/treeList/images/ss-b.png', // 关闭图标
		openedSign : '/'+bfsprojectName+'/component/treeList/images/ss.png', // 展开图标
		topclosedSign : '/'+bfsprojectName+'/component/treeList/images/up.png', // 关闭图标
		topopenedSign : '/'+bfsprojectName+'/component/treeList/images/down.png', // 展开图标
		speed : 500, // 展开动画效果时长
		color : undefined, // 字体颜色
		backColor : undefined, // 背景色
		borderColor : undefined, // 边框颜色
		selectedColor : '#fff', // 选中字体颜色
		highlightSelected : true, // 高亮显示选择
		showBorder : true, // 显示边框
		onNodeSelected : undefined, // 节点选中时执行的事件
		onStaTypeSelected : undefined, // 站点类型选中执行事件
		onMenuSelected : undefined,
		resetSize : undefined,
		onNodata : undefined
	// 菜单点击事件
	// onCheckBoxed:undefined//多选按钮点击事件
	};

	Tree.prototype = {
		remove : function() {
			this._destroy();
			$.removeData(this, 'plugin_' + pluginName);
		},

		_destroy : function() {

			if (this.initialized) {
				this.$element.remove();
				this.$element = null;

				// Switch off events
				this._unsubscribeEvents();
			}

			// Reset initialized flag
			this.initialized = false;
		},
		/* 初始化模板 */
		_loadTemplate : function(options) {
			var self = this;
			this.options = $.extend({}, Tree.defaults, options);
			this._template();
			resizeCallBackFun = options.resetSize;
			resetSize();
		},
		/* 加载模板文件 */
		_template : function() {
			var self = this;
			$.get("/"+bfsprojectName+"/component/treeList/treeList.html", function(
					source) {
				self.$element.append(source);
				// 
				if (self.options.showMenu) {
					var menuId = self._getUrlParam("menuId");
					self._templateData({}, menuId);
				} else {
					self._stationType(source);
				}
			});
		},
		/* 加载监测类型数据 */
		_stationType : function(source) {
			var self = this;
			var sys = self._getUrlParam("systemType");
			var stationStatus = self._getUrlParam("StationStatus");
			var rmote = self._getUrlParam("Rmote");
			if (rmote == null || rmote == undefined) {
				rmote = 0;
			}
			if (stationStatus == null || stationStatus == undefined) {
				stationStatus = "";
			}
			self._templateData({}, sys, stationStatus, rmote);
			
			/*var url = getProjectUrl("/GeneralCategory/generalCategoryByCategoryClass");
			var data = {
				categoryClass : sys
			};*/
		
			
			/* ajaxRequest(url, null, data, null,
			            function(source) {
				 if (source == false) {
						self._templateData({}, sys, stationStatus, rmote);
					} else {
						self._templateData(source, sys, stationStatus, rmote);
					}
			            }, null);*/
		},
		/* 加载菜单树数据 */
		_templateData : function(sourceData, Param, stationStatus, rmote) {
			var postData = {};
			var self = this;
			var options = self.options;
			// postData.Alarm = Number(options.showAlarm);
			postData.showArea = Number(options.showArea);
			postData.showOrg = Number(options.showOrg);
			postData.showStation = Number(options.showStation);
			postData.showRight = Number(options.showRights);
			postData.showRmote = Number(rmote);
			postData.monitorType = stationStatus;
			postData.systemType = self._getUrlParam("systemType");
			postData.checkAlarm = Number(options.checkAlarm);
			var url;
			if(options.dataUrl===""){
				url = "/gems/AreaOrgStnTree/treeList";
			}else{
				url = options.dataUrl;
			}
			 ajaxRequest(url, null, postData, null,
			            function(data) {
				 var source=sourceData;
					if (data.result == "ERROR") {
						return;
					}
					$("#open").on('click', function(event) {
						self._treeShow();
					});
					if (data.rows.length > 0) { 
						source.treeData = data.rows;
						source.defaults = options;
						self._setStateOpen(source.treeData);
						self.data = source;
						self._css(source);
					}else{
						self._setNoData();
					}
			            }, null);
		},
		/* 加载样式文件 */
		_css : function(data) {
			var self = this;
			/*$.get("/"+bfsprojectName+"/component/treeList/treeList.css", function(
					source) {
				$("<style>").attr({
					type : "text/css"
				}).text(source).appendTo("head");*/
				var templates = [];
				templates.push("searchTemplate");
				if (self.options.showAlarm) {
					templates.push("treeListAlarmTemplate");
				} else if (self.options.showMenu) {
					templates.push("menuListAlarmTemplate");
				} else {
					templates.push("treeListTemplate");
				}
				self._compile(templates, data);
				if (self.options.checkBoxCookied) {
					self._checkBoxCookie('check_box', self);
				} else {
					self._checkAll(undefined, self);
				}

				self._createNodes(data.treeData);
				self._selectLeaf();
			/*});*/
		},
		/* 初始化 */
		_init : function(options) {
			this._subscribeEvents();
			// 添加 [+]标志到树列表
			this.$element.find("li").each(
					function() {
						if ($(this).find("ul").size() != 0) {
							if($(this).hasClass("navtop")){
								/*$(this).find("a:first").append(
										"<span>" + options.topclosedSign + "</span>");*/
								$(this).find("a:first").css("background","url("+options.topclosedSign+") 218px no-repeat");
							}else{
							/*	$(this).find("a:first").append(
										"<span>" + options.closedSign + "</span>");*/
								$(this).find("a:first").css("background","url("+options.closedSign+") 218px no-repeat");
							}
							
							if ($(this).find("a:first").attr('href') == "#") {
								$(this).find("a:first").click(function() {
									return false;
								});
							}
						}
					});
			// 打开active 列表
			this.$element.find("li.active").each(
					function(index) {
						if (options.showMenuAll) {
							$(this).parents("ul").slideDown(options.speed);
							/*$(this).parents("ul").parent("li[name='navtop']").find(
									"span:first").html(options.topopenedSign);*/
							$(this).parents("ul").parent("li[name='navtop']").find("a:first").css("background","url("+options.topopenedSign+") 218px no-repeat");
							
								/*$(this).parents("ul").parent("li[name!='navtop']").find(
								"span:first").html(options.openedSign);*/
								$(this).parents("ul").parent("li[name!='navtop']").find("a:first").css("background","url("+options.openedSign+") 222px no-repeat");
								
							
						} else if (index == 0) {
							$(this).parents("ul").slideDown(options.speed);
							
								/*$(this).parents("ul").parent("li[name='navtop']").find(
										"span:first").html(options.topopenedSign);*/
								$(this).parents("ul").parent("li[name='navtop']").find("a:first").css("background","url("+options.topopenedSign+") 218px no-repeat");
								
/*									$(this).parents("ul").parent("li[name!='navtop']").find(
									"span:first").html(options.openedSign);*/
									$(this).parents("ul").parent("li[name!='navtop']").find("a:first").css("background","url("+options.openedSign+") 222px no-repeat");
									
								
							
						}
					});
		},
		/* 编译模板 */
		_compile : function(templates, data) {
			if (!templates) {
				return;
			}
			var i = 0, length = templates.length, html = "";
			this.$element.find("ul.nav1").remove();
			for (; i < length; i++) {
				html = template(templates[i], data);
				this.$element.append(html);
			}
			html = '<div id="open" class="shbtnShow">';
			html += '<a id="showTree" class="aShow" href="javascript:void(0);" onclick="openTree()"></a>';
			html += '</div>';
			$(".leftTree").parent().append(html);
			if (this.options.checkAlarm) {
				$("ul.nav1").css("margin-top",50);
				$(".checkAlarm").show();
				
			}else{
				$("ul.nav1").css("margin-top",10);
				$(".checkAlarm").hide();
			}
			this._init(this.options);
			resetSize();
		},
		/* 取消事件依赖监听 */
		_unsubscribeEvents : function() {
			$("#btnSearchTree").off("click");
			$("#txtSearch").off("keyup");
			$("#chk_all").off("click");
			$("input[name='chkStationType']").off("click");
			$("input[name='radStationType']").off("click");
			$("input[name='chkTree1Level']").off("click");
			$("input[name='chkTree2Level']").off("click");
			$("input[name='chkTree3Level']").off("click");
			$("#showalarm").off("click");
			$("#showall").off("click");

			this.$element.find("li a").off("click");
			if (this.options.showMenu) {
				if (typeof (this.options.onMenuSelected) === "function") {
					this.$element.off('menuSelected');
				}
			} else {
				if (typeof (this.options.onNodeSelected) === "function") {
					this.$element.off("nodeSelected");
				}
			}
			if (this.options.onStaTypeSelected === "function") {
				$("#chk_all").off('staTypeSelected');
			}
			if (this.options.onMenuSelected === "function") {
				this.$element.off("menuSelected");
			}
		},
		/* 事件依赖监听 */
		_subscribeEvents : function() {
			this._unsubscribeEvents();
			var self = this;
			this.$element.find("li a").on("click", function(event) {
				self._clickHandler(event, self)
			});
			$("#btnSearchTree").on("click", $.proxy(self._searchText, self));
			$("#txtSearch").on('keyup', function(event) {
				self._keyup(event, self)
			});
			$("input[name='chkStationType']").on('click', function(event) {
				self._checkSingle(event, self)
			});
			if (typeof (this.options.onStaTypeSelected) === 'function') {
				$("input[name='chkStationType']").on('staTypeSelected',
						this.options.onStaTypeSelected);
				$("#chk_all").on('staTypeSelected',
						this.options.onStaTypeSelected);
				$("input[name='radStationType']").on('staTypeSelected',
						this.options.onStaTypeSelected);
			}
			$("#chk_all").on('click', function(event) {
				self._checkAll(event, self);
			});
			$("input[name='radStationType']").on('click', function(event) {
				self._radStationType(event, self)
			});
			$("input[name='chkTree1Level']").on('click', function(event) {
				self._chkTree1Level(event, self);
			});
			$("input[name='chkTree2Level']").on('click', function(event) {
				self._chkTree2Level(event, self);
			});
			$("input[name='chkTree3Level']").on('click', function(event) {
				self._chkTree3Level(event, self);
			});
			$("input[name='chkTree4Level']").on('click', function(event) {
				self._chkTree4Level(event, self);
			});
			$("input[name='chkTree5Level']").on('click', function(event) {
				self._chkTree5Level(event, self);
			});
			$("#showalarm").on("click",function(){
				$("#showalarm").addClass("on");
				$("#showall").removeClass("on");
				self._searchTextAlarm();
			});
			$("#showall").on("click",function(){
				$("#showall").addClass("on");
				$("#showalarm").removeClass("on");
				self._searchTextAlarm();
			});
			if (this.options.showMenu) {
				if (typeof (this.options.onMenuSelected) === 'function') {
					this.$element.on('menuSelected',
							this.options.onMenuSelected);
				}
			} else {
				if (typeof (this.options.onNodeSelected) === 'function') {
					this.$element.on('nodeSelected',
							this.options.onNodeSelected);
				}
			}
			
		},
		_radStationType : function(event, $this) {
			var nodeId, obj;
			obj = $(event.target).parent();
			obj
					.find("input")
					.each(
							function() {
								if ($this.radioStationType != this.value) {
									$this.radioStationType = this.value;
									$this.checkStationType[0] = this.value;
									$this._filterStationType(
											$this.checkStationType,
											event.target.value,
											event.target.checked);
									// $this._searchText();
									if (typeof ($this.options.onStaTypeSelected) === 'function') {
										$this._triggerStaTypeSelectedEvent(
												[ $this.checkStationType ],
												event.target);
									}
								}
							});
		},
		_chkTree1Level : function(event, $this) {
			var nodeId, obj;
			obj = $(event.target).parent().next();
			if (obj.length == 0) {
				obj = $(event.target).parent();
			}
			obj.find("input").each(function() {
				this.checked = event.target.checked;
				$this._setMulitCheck(this, this.checked);
			});

		},
		_chkTree2Level : function(event, $this) {
			var curKey = event.which;
			if (curKey == 13) {
				this._searchText();
			}
			var nodeId, obj;
			obj = $(event.target).parent().next();
			if (obj.length == 0) {
				obj = $(event.target).parent();
			}
			var navtopObj=$(event.target).closest(".navtop");
			if(event.target.checked){
				var objchecks=$(navtopObj).find("input[name=chkTree2Level]:checked");
				var objs=$(navtopObj).find("input[name=chkTree2Level]");
				if(objchecks.length === objs.length){
					obj=$(navtopObj);
				}else{
					 objchecks=$(event.target).parents("li .nav2bg").find(".nav3bg input:checked");
					 objs=$(event.target).parents("li .nav2bg").find(".nav3bg input");
					if(objchecks.length === objs.length){
						obj=$(event.target).parents("li .nav2bg");
					}
				}
			}else{
				var objchecks=$(navtopObj).find("input[name=chkTree2Level]").not(":checked");
				var objs=$(navtopObj).find("input[name=chkTree2Level]");
				if(objchecks.length === objs.length){
					obj=$(navtopObj);
				}else{				
					$(navtopObj).find("input[name=chkTree1Level]").each(function() {
						this.checked = event.target.checked;
						$this._setMulitCheck(this, this.checked);
					});
				}
			}
			obj.find("input").each(function() {
				this.checked = event.target.checked;
				$this._setMulitCheck(this, this.checked);
			});
		},
		_chkTree3Level : function(event, $this) {
			var curKey = event.which;
			if (curKey == 13) {
				this._searchText();
			}
			var nodeId, obj;
			obj = $(event.target).parent().next();
			if (obj.length === 0) {
				obj = $(event.target).parent();
			}
			var navtopObj=$(event.target).closest(".navtop");
			if(event.target.checked){
				var objchecks=$(".nav1").find("input[name=chkTree3Level]:checked");
				var objs=$(".nav1").find("input[name=chkTree3Level]");
				if(objchecks.length === objs.length){
					obj=$(navtopObj);
				}else{
					objchecks=$(event.target).parents("li .nav2bg").find(".nav3bg input[name=chkTree3Level]:checked");
					objs=$(event.target).parents("li .nav2bg").find(".nav3bg input[name=chkTree3Level]");
					if(objchecks.length === objs.length){
						obj=$(event.target).parents("li .nav2bg");
					}
				}
			}else{
				var objchecks=$(".nav1").find("input[name=chkTree3Level]").not(":checked");
				var objs=$(".nav1").find("input[name=chkTree3Level]");
				if(objchecks.length === objs.length){
					obj=$(navtopObj);
				}else{
					objchecks=$(event.target).parents("li .nav2bg").find(".nav3bg input[name=chkTree3Level]:checked");
					objs=$(event.target).parents("li .nav2bg").find(".nav3bg input[name=chkTree3Level]");
					if(objchecks.length !== objs.length){
						$(event.target).parents("li .nav2bg").find("input[name=chkTree2Level]").each(function() {
							this.checked = event.target.checked;
							$this._setMulitCheck(this, this.checked);
						});
					}
					$(navtopObj).find("input[name=chkTree1Level]").each(function() {
						this.checked = event.target.checked;
						$this._setMulitCheck(this, this.checked);
					});
				}
			}
			
			obj.find("input").each(function() {
				this.checked = event.target.checked;
				$this._setMulitCheck(this, this.checked);
			});
		},
		_chkTree4Level : function(event, $this) {
			var curKey = event.which;
			if (curKey == 13) {
				this._searchText();
			}
			var nodeId, obj;
			obj = $(event.target).parent().next();
			if (obj.length === 0) {
				obj = $(event.target).parent();
			}
			var navtopObj=$(event.target).closest(".navtop");
			$(event.target).parents("li .nav5bg").find("input[name=chkTree5Level]").each(function() {
				this.checked = event.target.checked;
				$this._setMulitCheck(this, this.checked);
			});
			if(event.target.checked){
				var objchecks=$(navtopObj).find(".leaf input:checked");
				var objs=$(navtopObj).find(".leaf input");
				if(objchecks.length === objs.length){
					obj=$(navtopObj);
				}else{				
					objchecks=$(event.target).parents("li .nav3bg").find(".nav4bg input[name=chkTree4Level]:checked");
					objs=$(event.target).parents("li .nav3bg").find(".nav4bg input[name=chkTree4Level]");
					if(objchecks.length === objs.length){
						$(event.target).parents("li .nav3bg").find("input[name=chkTree3Level]").each(function() {
							this.checked = event.target.checked;
							$this._setMulitCheck(this, this.checked);
						});
						objchecks=$(event.target).parents("li .nav2bg").find(".nav3bg input[name=chkTree3Level]:checked");
						objs=$(event.target).parents("li .nav2bg").find(".nav3bg input[name=chkTree3Level]");
						if(objchecks.length === objs.length){
							$(event.target).parents("li .nav2bg").find("input[name=chkTree2Level]").each(function() {
								this.checked = event.target.checked;
								$this._setMulitCheck(this, this.checked);
							});
						}						
					}					
				}
			}else{
				var objchecks=$(navtopObj).find(".leaf input").not(":checked");
				var objs=$(navtopObj).find(".leaf input");
				if(objchecks.length === objs.length){
					obj=$(navtopObj);
				}else{
					objchecks=$(event.target).parents("li .nav3bg").find(".nav4bg input[name=chkTree4Level]:checked");
					objs=$(event.target).parents("li .nav3bg").find(".nav4bg input[name=chkTree4Level]");
					if(objchecks.length !== objs.length){
						$(event.target).parents("li .nav3bg").find("input[name=chkTree3Level]").each(function() {
							this.checked = event.target.checked;
							$this._setMulitCheck(this, this.checked);
						});
						$(event.target).parents("li .nav2bg").find("input[name=chkTree2Level]").each(function() {
							this.checked = event.target.checked;
							$this._setMulitCheck(this, this.checked);
						});
					} 
					$(navtopObj).find("input[name=chkTree1Level]").each(function() {
						this.checked = event.target.checked;
						$this._setMulitCheck(this, this.checked);
					});
				}
			}
			
			obj.find("input").each(function() {
				this.checked = event.target.checked;
				$this._setMulitCheck(this, this.checked);
			});
		},
		_chkTree5Level : function(event, $this) {
			var curKey = event.which;
			if (curKey == 13) {
				this._searchText();
			}
			var nodeId, obj;
			obj = $(event.target).parent().next();
			if (obj.length === 0) {
				obj = $(event.target).parent();
			}
			var navtopObj=$(event.target).closest(".navtop");
			if(event.target.checked){
				var objchecks=$(navtopObj).find(".leaf input:checked");
				var objs=$(navtopObj).find(".leaf input");
				if(objchecks.length === objs.length){
					obj=$(navtopObj);
				}else{
					objchecks=$(event.target).parents("li .nav4bg").find(".nav5bg input[name=chkTree5Level]:checked");
					objs=$(event.target).parents("li .nav4bg").find(".nav5bg input[name=chkTree5Level]");
					if(objchecks.length === objs.length){
						obj=$(event.target).parents("li .nav4bg");
						objchecks=$(event.target).parents("li .nav3bg").find(".nav4bg input[name=chkTree4Level]:checked");
						objs=$(event.target).parents("li .nav3bg").find(".nav4bg input[name=chkTree4Level]");
						if(objchecks.length === objs.length){
							$(event.target).parents("li .nav3bg").find("input[name=chkTree3Level]").each(function() {
								this.checked = event.target.checked;
								$this._setMulitCheck(this, this.checked);
							});
							objchecks=$(event.target).parents("li .nav2bg").find(".nav3bg input[name=chkTree3Level]:checked");
							objs=$(event.target).parents("li .nav2bg").find(".nav3bg input[name=chkTree3Level]");
							if(objchecks.length === objs.length){
								$(event.target).parents("li .nav2bg").find("input[name=chkTree2Level]").each(function() {
									this.checked = event.target.checked;
									$this._setMulitCheck(this, this.checked);
								});
							}
						}											
					}					
				}
			}else{
				var objchecks=$(navtopObj).find(".leaf input").not(":checked");
				var objs=$(navtopObj).find(".leaf input");
				if(objchecks.length === objs.length){
					obj=$(navtopObj);
				}else{
					objchecks=$(event.target).parents("li .nav4bg").find(".nav5bg input[name=chkTree5Level]:checked");
					objs=$(event.target).parents("li .nav4bg").find(".nav5bg input[name=chkTree5Level]");
					if(objchecks.length !== objs.length){
						$(event.target).parents("li .nav4bg").find("input[name=chkTree4Level]").each(function() {
							this.checked = event.target.checked;
							$this._setMulitCheck(this, this.checked);
						});
						$(event.target).parents("li .nav3bg").find("input[name=chkTree3Level]").each(function() {
							this.checked = event.target.checked;
							$this._setMulitCheck(this, this.checked);
						});
						$(event.target).parents("li .nav2bg").find("input[name=chkTree2Level]").each(function() {
							this.checked = event.target.checked;
							$this._setMulitCheck(this, this.checked);
						});
					} 
					$(navtopObj).find("input[name=chkTree1Level]").each(function() {
						this.checked = event.target.checked;
						$this._setMulitCheck(this, this.checked);
					});
				}
			}
			
			obj.find("input").each(function() {
				this.checked = event.target.checked;
				$this._setMulitCheck(this, this.checked);
			});
		},
		_setMulitCheck : function(checkbox, checked) {
			if(!$(checkbox).parent().parent().hasClass("leaf")){
				return;
			}
			var nodeId = this._findNodeId(checkbox);
			var index = $.inArray(nodeId, this.mulitCheck);
			if (!checked) {
				if (index > -1) {
					this.mulitCheck.splice(index, 1); // 移除Id
				}
			} else {
				if (index == -1) {
					if (this._isLeaf(nodeId)) {
						this.mulitCheck.push(nodeId);
					}
				}
			}

		},
		/* 选中叶子节点 */
		_selectLeaf : function() {
			var nodes = this.$element.find("li a");
			var topNodes =this.$element.find("li.navtop input[name='chkTree1Level']");
			var topObjs =this.$element.find("li.navtop");
			var firstNode = this._findFirstNode();
			var obj=this;
			if (firstNode != null) {
				if (this.options.mulitCheck) {
					if(!this.options.checkOneStation) {
						this.$element.find("li a input").prop("checked",true);
						for(var i=0;i<topObjs.length;i++){
							$(topObjs[i]).find("input").each(function() {							
								obj.checked = true;
								obj._setMulitCheck(this,true);
							});
							$($(topObjs[i])).find(".leaf").addClass("on");
							if(i === topNodes.length-1){
								$(topObjs[i]).find("input[name='chkTree1Level']").prop("checked",false);
								$(topObjs[i]).find("input[name='chkTree1Level']").trigger("click");
								break;
							}
						}
					} else {
						var nodess = [];
						firstNode.checked = true;
						this.mulitCheck.push(firstNode.id);
						nodess.push(firstNode);	
						$(topObjs[0]).find("input[name='chkTree4Level']")[0].checked = true;
						this._triggerNodeSelectedEvent(nodess);

					}
					
				}else{
					for (var i = 0; i < nodes.length; i++) {
						if ($(nodes[i]).attr("data-nodeid") === firstNode.id) {
							$(nodes[i]).trigger("click");
							break;
						}
					}
				}
			}
		},

		_findNodeId : function(target) {
			var nodeId;
			if ($(target).attr('data-nodeid')) {
				nodeId = $(target).attr('data-nodeid');
			} else {
				nodeId = $(target).parent().attr('data-nodeid');
			}
			if ($(target).attr('data-linkUrl')) {
				var linkUrl = $(target).attr('data-linkUrl');
				// GetMenuLinkUrl(linkUrl);
			}
			return nodeId;

		},
		_findFirstNode : function() {
			var node;
			for (var i = 0; i < this.nodes.length; i++) {
				node = this.nodes[i];
				if (node) {

					if (node.state == "open") {

						break;
					} else {
						node = null;
					}
				}
			}
			return node;
		},
		/* 设置树的第一级为打开状态 */
		_setStateOpen : function(nodes) {
			var self = this;
			for (var i = 0; i < nodes.length; i++) {
				if (nodes[i].children && nodes[i].children.length > 0) {
					self._setStateOpen(nodes[i].children);
				} else {
					nodes[i].state = "open";
					// break;
				}
				// break;
			}
		},
		/* 搜索框回车事件 */
		_keyup : function(event) {
			var curKey = event.which;
			if (curKey == 13) {
				this._searchText();
			}
		},
		/* 树列表点击事件 */
		_clickHandler : function(event, $this) {
			var target = $(event.target);
			if(target.get(0).tagName==="IMG"){
				target=$(target).parent().parent();
			}
			var clickByCheckbox = $(event.target).attr("class") == "ckbox";
			if (clickByCheckbox) {
				target = $(event.target).parent();
			} else {
				var parents, visible;
				if ($(target).parent().find("ul").size() != 0) {
					if ($this.options.accordion) {
						// Do nothing when the list is open
						if (!$(target).parent().find("ul").is(':visible')) {
							parents = $(target).parent().parents("ul");
							visible = $this.$element.find("ul.nav1").find(
									"ul:visible");
							visible
									.each(function(visibleIndex) {
										var close = true;
										parents
												.each(function(parentIndex) {
													if (parents[parentIndex] == visible[visibleIndex]) {
														close = false;
														return false;
													}
												});
										if (close) {
											if ($(target).parent().find("ul") != visible[visibleIndex]) {
												/*
												 * $(visible[visibleIndex]).slideUp($this.options.speed,
												 * function() {//让可见的隐藏
												 * $(this).parent("li").find("span:first").html($this.options.closedSign);//'[+]'
												 * });
												 */

											}
										}
									});
						}
					}
					if ($(target).parent().find("ul:first").is(":visible")) {
						$(target).parent().find("ul:first").slideUp(
								$this.options.speed,
								function() {
									if($(target).parent("li").hasClass("navtop")){
										/*$(target).parent("li").find("span:first")
										.delay($this.options.speed).html(
												$this.options.topclosedSign);*/
										$(target).parent("li").find("span:first")
										.delay($this.options.speed);
										$(target).parent("li").find("a:first").css("background","url("+$this.options.topclosedSign+") 218px no-repeat");
										
									}else{
										/*$(target).parent("li").find("span:first")
										.delay($this.options.speed).html(
												$this.options.closedSign);*/
										$(target).parent("li").find("span:first")
										.delay($this.options.speed);
										$(target).parent("li").find("a:first").css("background","url("+$this.options.closedSign+") 222px no-repeat");
										
									}
								});

					} else {
						$(target).parent().find("ul:first").slideDown(
								$this.options.speed,
								function() {
									if($(target).parent("li").hasClass("navtop")){
										/*$(target).parent("li").find("span:first")
										.delay($this.options.speed).html(
												$this.options.topopenedSign);*/
										$(target).parent("li").find("span:first")
										.delay($this.options.speed);
										$(target).parent("li").find("a:first").css("background","url("+$this.options.topopenedSign+") 218px no-repeat");
										
									}else{
										/*$(target).parent("li").find("span:first")
										.delay($this.options.speed).html(
												$this.options.openedSign);*/
										$(target).parent("li").find("span:first")
										.delay($this.options.speed);
										$(target).parent("li").find("a:first").css("background","url("+$this.options.openedSign+") 222px no-repeat");
										
									}
								});
					}
				}
			}
			// 改变选中的背景色及触发选中事件
			var nodes;
			// 多选并且点击的是checkbox
			if ($this.options.mulitCheck && clickByCheckbox) {
				nodes = $this._findNode(target);
			} else if ($this.options.mulitCheck) {
				// 是叶子节点执行后续操作
				if ($this._isLeaf($this._findNodeId(target))) {
					nodes = $this._findNode(target);
				} else {
					return;
				}

			} else {
				nodes = $this._findNode(target);
			}
			if (nodes.length) {
				// 设置选中背景色
				if (!$this.options.mulitCheck) {
					$("li").css("background", "");
					$("li").removeClass("on");
					$(target).parent().addClass("on");
					$this._triggerNodeSelectedEvent(nodes);
				} else {
					$(target)
							.parent()
							.find("a")
							.each(
									function() {
										for (var i = 0; i < nodes.length; i++) {
											if ($(this).attr('data-nodeid') == nodes[i].id) {
												// 背景色选中样式
												$(target).parent().addClass("on");
												break;
											} else {
												$(this).parent().css(
														"background", "");
											}
										}

									});
					$this._triggerNodeSelectedEvent(nodes);
				}

			} else {
				if (clickByCheckbox) {
					$this._triggerNodeSelectedEvent(nodes);
				}
				$(target).parent().parent().find("li").css("background", "");

			}
		},
		_isLeaf : function(nodeId) {
			var node = this._findNodeById(nodeId);
			if (node) {
				return true;
			}
			return false;
		},
		/* 查找当前选中节点的数据 */
		_findNode : function(target) {
			var returnNodeArr = [];
			var nodeId, node;
			if (this.options.mulitCheck) {
				for (var i = 0; i < this.mulitCheck.length; i++) {
					node = this._findNodeById(this.mulitCheck[i]); // this.nodes[this.mulitCheck[i]];
					if (node) {
						returnNodeArr.push(node);
					}
				}
			} else {
				nodeId = this._findNodeId(target);
				node = this._findNodeById(nodeId);
				if (node) {
					returnNodeArr.push(node);
				}

			}
			return returnNodeArr;
		},
		/* 根据节点ID，查找节点 */
		_findNodeById : function(nodeId) {
			var node;
			for (var i = 0; i < this.nodes.length; i++) {
				if (this.nodes[i].id == nodeId) {
					node = this.nodes[i];
					break;
				}
			}
			return node;
		},
		/* 根据树列表数据，生成节点 */
		_createNodes : function(nodes, nodeId) {

			for (var i = 0; i < nodes.length; i++) {
				if (nodes[i].children&&nodes[i].children.length>0) {
					this._createNodes(nodes[i].children, nodes[i].id);
				} else {
					var newNode = $.extend(true, {}, nodes[i]);
					if (this.options.showOrg) {
						if (nodeId) {
							newNode.OrgId = nodeId;
						} else {
							newNode.OrgId = nodes[i].id;
						}
					}
					this.nodes.push(newNode);
				}
			}
		},
		// 触发 nodeSelected 事件
		_triggerNodeSelectedEvent : function(node) {
			if (!node) {
				return;
			}
			if (this.options.showMenu) {
				this.$element.trigger('menuSelected', [ node ]);
			} else {
				this.$element.trigger('nodeSelected', [ node ]);
			}
		},
		// 触发 onStaTypeSelected 事件
		_triggerStaTypeSelectedEvent : function(checkStationType, obj) {
			if (checkStationType.length == 0) {
				return;
			}
			$(obj).trigger('staTypeSelected', checkStationType);
		},
		/* 搜索按钮事件 */
		_searchHigtText : function(event) {
			var text = $.trim($("#txtSearch").val());
			var data = {};
			var searchSource = $.extend(true, [], this.data.treeData);
			$("#tree").unhighlight();
			$("#tree .leaf").highlight(text);
			$(".nav1").stop(true);
			if(text===""){ 
				this._selectLeaf();			
				return;
			}
			this.mulitCheck=[];
			if($(".highlight").length===0){
				$("input[type='checkbox']").prop("checked",false); // 取消选中全部checkbox框				
				var topObjs =this.$element.find("li.navtop");
				$(topObjs[0]).find("input[name='chkTree1Level']").prop("checked",true);
				$(topObjs[0]).find("input[name='chkTree1Level']").trigger("click");
				$("#noTreeData").show();
				var t=setTimeout("$('#noTreeData').hide();",3000)
				return;
			}
			var index=0;
			$("#tree li").each(function(p){
				if($($(".highlight")[0]).parent().data("nodeid")==$(this).find("a").data("nodeid")&&$($(".highlight")[0]).parent().parent().attr("name")==$(this).attr("name")){
					index=p;
				}
			});
			$(".nav1").animate({scrollTop: index*45}, 1000);
			var nodes=[];
			var nodeid,node;
			if(!this.options.mulitCheck){
			 nodeid=$($(".highlight")[0]).parent().data("nodeid");
			 node=this._findNodeById(nodeid); 
			 $(".leaf").removeClass("on");
			 $($(".highlight")[0]).parent().parent().addClass("on");
			 nodes.push(node);			
			}else{
				$("input[type='checkbox']").prop("checked",false);
				for(var i=0;i<$(".highlight").length;i++){
					 nodeid=$($(".highlight")[i]).parent().data("nodeid");
					 if($($(".highlight")[i]).prev("input")[0] !== undefined){
						 $($(".highlight")[i]).prev("input")[0].checked = true;
					 }
					 if($($(".highlight")[i]).parent().parent().hasClass("leaf")){
					 	 node=this._findNodeById(nodeid); 					
					 	 nodes.push(node);
						 var index = $.inArray(nodeid.toString(), this.mulitCheck);
						 if(index==-1){
							 this.mulitCheck.push(nodeid.toString());
						 }
					 }					
				}
			}
			this._triggerNodeSelectedEvent(nodes);
			$(".navtop").each(function(i){
				$($(".navtop")[i]).find(".nav2bg").each(function(j){
					$(this).find(".nav3bg").each(function(m){
						$(this).find(".nav4bg").each(function(n){
							if($(this).find(".nav5bg input[name='chkTree5Level']:checked").length!==0&&$(this).find(".nav5bg").length === $(this).find(".nav5bg input[name='chkTree5Level']:checked").length){
								$(this).find("input[name='chkTree4Level']")[0].checked = true;
							}
						});
						if($(this).find(".nav4bg input[name='chkTree4Level']:checked").length!==0&&$(this).find(".nav4bg").length === $(this).find(".nav4bg input[name='chkTree4Level']:checked").length){
							$(this).find("input[name='chkTree3Level']")[0].checked = true;
						}
					});
					if($(this).find(".nav3bg input[name='chkTree3Level']:checked").length!==0&&$(this).find(".nav3bg").length === $(this).find(".nav3bg input[name='chkTree3Level']:checked").length){
						$(this).find("input[name='chkTree2Level']")[0].checked = true;
					}
				});
				if($(this).find(".nav2bg input[name='chkTree2Level']:checked").length!==0&&$(this).find(".nav2bg").length === $(this).find(".nav2bg input[name='chkTree2Level']:checked").length){
					$(this).find("input[name='chkTree1Level']")[0].checked = true;
				}
			});

			/*if ($("input[name='chkStationType']").length <= 1) {
				if (text != "") {
					this._search(searchSource, text);
				}
			} else {
				this._search(searchSource, text);
			}
			data.treeData = searchSource;
			data.defaults = this.options;*/
			/*this._setStateOpen(data.treeData);
			this.nodes = []; // 清空已存在的节点
			this._createNodes(data.treeData);
			var templates = [];
			if (this.options.showAlarm) {
				templates.push("treeListAlarmTemplate");
			} else if (this.options.showMenu) {
				templates.push("menuListAlarmTemplate");
			} else {
				templates.push("treeListTemplate");
			}
			this._compile(templates, data);

			this._selectLeaf();*/
		},
		_searchText : function(event) {
			if(!this.options.mulitCheck){
				this._searchHigtText(event);
			}else{
				this._searchHigtText(event);
				/*var text = $.trim($("#txtSearch").val());
				var data = {};
				var searchSource = $.extend(true, [], this.data.treeData);
				if ($("input[name='chkStationType']").length <= 1) {
					if (text != "") {
						this._search(searchSource, text);
					}
				} else {
					this._search(searchSource, text);
				}
				data.treeData = searchSource;
				data.defaults = this.options;
				this._setStateOpen(data.treeData);
				this.nodes = []; // 清空已存在的节点
				this._createNodes(data.treeData);
				var templates = [];
				if (this.options.showAlarm) {
					templates.push("treeListAlarmTemplate");
				} else if (this.options.showMenu) {
					templates.push("menuListAlarmTemplate");
				} else {
					templates.push("treeListTemplate");
				}
				this._compile(templates, data);

				this._selectLeaf();*/
			}			
		},
		_searchTextAlarm : function() {
			//if(!this.options.mulitCheck){
				//this._searchHigtText(event);
			//}else{
				//this._searchHigtText(event);
				var text = $.trim($("#txtSearch").val());
				var data = {};
				var searchSource = $.extend(true, [], this.data.treeData);
				this._searchAlarm(searchSource, text);
				data.treeData = searchSource;
				data.defaults = this.options;
				this._setStateOpen(data.treeData);
				this.nodes = []; // 清空已存在的节点
				this._createNodes(data.treeData);
				var templates = [];
				if (this.options.showAlarm) {
					templates.push("treeListAlarmTemplate");
				} else if (this.options.showMenu) {
					templates.push("menuListAlarmTemplate");
				} else {
					templates.push("treeListTemplate");
				}
				this._compile(templates, data);

				this._selectLeaf();
				if (this.options.checkAlarm) {
					$("ul.nav1").css("margin-top",50);
					$(".checkAlarm").show();
					
				}else{
					$("ul.nav1").css("margin-top",10);
					$(".checkAlarm").hide();
				}
		//	}			
		},
		/* 获取URL参数 */
		_getUrlParam : function(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var matchResult = window.location.search.substr(1).match(reg);
			if (matchResult != null) {
				return unescape(matchResult[2]);
			}
			return null;
		},
		/* 数据搜索 */
		_searchAlarm : function(nodes, text) {
			var index;
			for (var i = nodes.length - 1; i >= 0; i--) {
				if($(".checkAlarm .menu-tab.on").attr("id")==="showalarm"){
					if(nodes[i].data!=null&&(isEmpty(nodes[i].data.isAlarm)||nodes[i].data.isAlarm===0)){
						nodes.splice(i, 1);
						continue;
					}
				}
				if ((text != "" && nodes[i].text.indexOf(text) == -1)
						|| text == "") {
					if (nodes[i].children) {
						if (nodes[i].children.length == 0) {
							delete nodes[i].children;
						} else {
							this._searchAlarm(nodes[i].children, text);
						}
					}
					if (nodes[i].children) {
						if (nodes[i].children.length == 0) {
							nodes.splice(i, 1);
						}
					} else {
						if (this.checkStationType) {
							index = $.inArray(nodes[i].Type + "",
									this.checkStationType); // 监测类型是否选中
							// 搜索的关键字不为空，且监测类型存在，则删除该条数据
							if (text != "" && index > -1) {
								nodes.splice(i, 1);
							}
							/*if (index == -1) {
								nodes.splice(i, 1);
							}*/
						} else {
							nodes.splice(i, 1);
						}
					}
				} else {
					if (this.checkStationType) {
						if (this.checkStationType.length > 0) {
							index = $.inArray(nodes[i].Type + "",
									this.checkStationType); // 监测类型是否选中
						} else {
							index = nodes[i].text.indexOf(text);
						}
						// 搜索的关键字不为空，且监测类型存在，则删除该条数据
						if (text != "" && index == -1) {
							if (nodes[i].children) {
								if (nodes[i].children.length == 0) {
									nodes.splice(i, 1);
								}
							} else {
								nodes.splice(i, 1);
							}
						}
					}
				}

			}
		},
		/* 数据搜索 */
		_search : function(nodes, text) {
			var index;
			for (var i = nodes.length - 1; i >= 0; i--) {
				if ((text != "" && nodes[i].text.indexOf(text) == -1)
						|| text == "") {
					if (nodes[i].children) {
						if (nodes[i].children.length == 0) {
							delete nodes[i].children;
						} else {
							this._search(nodes[i].children, text);
						}
					}
					if (nodes[i].children) {
						if (nodes[i].children.length == 0) {
							nodes.splice(i, 1);
						}
					} else {
						if (this.checkStationType) {
							index = $.inArray(nodes[i].Type + "",
									this.checkStationType); // 监测类型是否选中
							// 搜索的关键字不为空，且监测类型存在，则删除该条数据
							if (text != "" && index > -1) {
								nodes.splice(i, 1);
							}
							if (index == -1) {
								nodes.splice(i, 1);
							}
						} else {
							nodes.splice(i, 1);
						}
					}
				} else {
					if (this.checkStationType) {
						if (this.checkStationType.length > 0) {
							index = $.inArray(nodes[i].Type + "",
									this.checkStationType); // 监测类型是否选中
						} else {
							index = nodes[i].text.indexOf(text);
						}
						// 搜索的关键字不为空，且监测类型存在，则删除该条数据
						if (text != "" && index == -1) {
							if (nodes[i].children) {
								if (nodes[i].children.length == 0) {
									nodes.splice(i, 1);
								}
							} else {
								nodes.splice(i, 1);
							}
						}
					}
				}

			}
		},
		/* 全部选择 */
		_checkAll : function(event, $this) {
			// 默认只有一个，不做任何操作
			if ($("input[name='chkStationType']").length <= 1) {
				return;
			}
			var chkAll;
			if (event) {
				chkAll = event.target;
			} else {
				if (!$this.options.stationTypeCheckOne) {
					chkAll = $("#chk_all")[0];
					chkAll.checked = true; // 选中全部checkbox框
				}

			}
			$this.checkStationType = [];
			$("input[name='chkStationType']").each(function(index) {
				this.checked = chkAll.checked;
				if (this.checked) {
					$this.checkStationType.push($(this).val());
				}
				if ($this.options.stationTypeCheckOne) {
					return false;
				}

			});
			$this._filterStationType($this.checkStationType, chkAll.value,
					chkAll.checked);
			if (typeof (this.options.onStaTypeSelected) === 'function') {
				var index = $.inArray('all', $this.checkStationType);
				if (index != -1) {
					$this.checkStationType.splice(index, 1);
				}
				this._triggerStaTypeSelectedEvent([ $this.checkStationType ],
						chkAll);
				document.cookie = 'check_box=' + $this.checkStationType;
			}
			if (!$this.firstLoad) {
				$("#btnSearchTree").trigger("click");
			}
			$this.firstLoad = false;
		},
		/* cookie初始化复选框 */
		_checkBoxCookie : function(name, $this) {
			var cookies = document.cookie.split(';');
			var array = [];
			var chkAll = $("#chk_all")[0];
			chkAll.checked = true; // 选中全部checkbox框
			if (!cookies.length)
				return '';
			for (var i = 0; i < cookies.length; i++) {
				var pair = cookies[i].split('=');
				if ($.trim(pair[0]) == name) {
					array = $.trim(pair[1]).split(',');
				}
			}
			$("input[name='chkStationType']").each(function() {
				if ($.inArray(this.value, array) != -1) {
					this.checked = true;
					$this.checkStationType.push($(this).val());
				} else {
					chkAll.checked = false; // 没有全选中
				}

			});
			if (typeof (this.options.onStaTypeSelected) === 'function') {
				var index = $.inArray('all', $this.checkStationType);
				if (index != -1) {
					$this.checkStationType.splice(index, 1);
				}
				this._triggerStaTypeSelectedEvent([ $this.checkStationType ],
						chkAll);
			}
		},
		/* 监测类型选择 */
		_checkSingle : function(event, $this) {
			if (!$("chkStationType").checked) {
				$("#chk_all").attr("checked", false);
			}
			var chsubNum = $("input[name='chkStationType']").length; // 获取subcheck的个数
			var checkedsubNum = $("input[type='checkbox'][name='chkStationType']:checked").length; // 获取选中的subcheck的个数
			if (checkedsubNum == chsubNum) {
				$("#chk_all")[0].checked = true;
			}
			$this._filterStationType($this.checkStationType,
					event.target.value, event.target.checked);
			if (typeof (this.options.onStaTypeSelected) === 'function') {
				this._triggerStaTypeSelectedEvent([ $this.checkStationType ],
						event.target);
				document.cookie = 'check_box=' + $this.checkStationType;
			}
			$("#btnSearchTree").trigger("click");
			// $this._searchtext(event);
		},
		/* 过滤监测类型 */
		_filterStationType : function(checkStationType, value, checked) {
			if (!checkStationType) {
				return;
			}
			var index = $.inArray(value, checkStationType);

			if (checked && index == -1) {
				// 选中，值不存在，添加
				checkStationType.push(value);
			} else if (!checked && index > -1) {
				// 取消选择，删除选中的值
				checkStationType.splice(index, 1);
			}
		},
		_treeShow:function(){
			/*if($("#open").hasClass("btn-left")){
				showTree = false;
				//$(".leftTree").animate({"left":0},"slow");
				//$(".leftTree").hide();
				//$("#open").removeClass("btn-left").addClass("btn-right");
				openTree();
				//$("#open").css("left", "0px");
			}else{
				showTree = true;
				//$(".leftTree").animate({"left":0},"slow");
				//$(".leftTree").show();
				//$("#open").removeClass("btn-right").addClass("btn-left");
				openTree();
			}*/
			openTree();			
		},
		_setNoData:function(){
			this.options.onNodata();
		}
	};
	var logError = function(message) {
		if (window.console) {
			window.console.error(message);
		}
	};
	// 防止多个实例，处理更新和方法调用
	$.fn[pluginName] = function(options, args) {
		return this.each(function() {
			var self = $.data(this, 'plugin_' + pluginName);
			if (typeof options === 'string') {
				if (!self) {
					logError('未能初始化, 不能调用方法 : ' + options);
				} else if (!$.isFunction(self[options])
						|| options.charAt(0) === '_') {
					logError('未能找到匹配的方法 : ' + options);
				} else {
					if (typeof args === 'string') {
						args = [ args ];
					}
					self[options].apply(self, args);
				}
			} else {
				if (!self) {
					$.data(this, 'plugin_' + pluginName, new Tree(this, $
							.extend(true, {}, options)));
				} else {
					self._init(options);
				}
			}
		});
	};

})(jQuery, window, document);

var showTree = true;
var resizeCallBackFun = null;
function openTree() {
	
	if (showTree) {
		showTree = false;		
		$("#open").addClass("btn-right");
		$("#open").removeClass("btn-left");
		$("#showTree").addClass("aHide");
		$("#showTree").removeClass("aShow");
		$(".leftTree").css("display", "none");
	} else {
		showTree = true;		
		$("#open").addClass("btn-left");
		$("#open").removeClass("btn-right");
		$("#showTree").addClass("aShow");
		$("#showTree").removeClass("aHide");
		$(".leftTree").css("display", "block");
	}
	var page = getTreePageSize();
	$("#open").css("left", page.treeWidth + "px");
	
	$(window).trigger("resize");
	
	if (resizeCallBackFun != null && resizeCallBackFun != undefined 
		&& typeof (resizeCallBackFun) === 'function') {
		resizeCallBackFun();
	}
}

// 当窗口改变时变化
$(window).resize(function() {
	resetSize();
});

function resetSize() {
	var page = getTreePageSize();
	$(".main").css("width", page.width + "px");
	$(".main").css("height", page.height + "px");
	
	$(".leftTree").css("width", page.treeWidth + "px");
	$(".leftTree").css("height", page.height + "px");
	if($(".checkAlarm").css("display")=="none"){
		$(".nav1").css("height", (page.height-54) + "px");
	}else{
		$(".nav1").css("height", (page.height-104) + "px");
	}
	
	$("#tree").css("width", (page.treeWidth - 2) + "px");
	
	var openwidth=0;
	if($("#open").length>0){
		$("#open").css("left", page.treeWidth + "px");
		//openwidth=$("#open").width();
		openwidth=2;
	}
	$(".content").css("width", (page.contentWidth-openwidth) + "px");
	$(".content").css("height", page.height + "px");
	$(".n-right").css("width", (page.contentWidth-openwidth)+ "px");
	$(".n-right").css("height", page.height + "px");
	//$(".list").css("height", page.height - $(".search").height() - 16); 
	var refurbishHeight=0;
	var chartHeight = 0;
	if($("#refurbishTimeId").length>0){
		if ($("#polluteCodeCharts").is(":hidden")) {
			chartHeight = 0;
		} else {
			chartHeight = $("#polluteCodeCharts").height();
		}
		refurbishHeight=$("#refurbishTimeId").outerHeight();		
	}
	if($("#TabsHistory").length>0){
		$("#TabsHistory").css("height",page.height - $(".n-dttitle").outerHeight()-10);
		var contentHeight=page.height - $(".n-dttitle").outerHeight()-39;
		
		$(".list").css("height",contentHeight-8);
		//$("#TabsHistory iframe").css("height",contentHeight-39);
		//$("#TabsHistory iframe").contents().find('.list').css("height",contentHeight-39);
	}else if($(".gearingchart").length>0){
		$(".list").css("height",page.height - $(".n-dttitle").outerHeight()-chartHeight-refurbishHeight-330-8);
	}else if($(".colorinfo").length>0){
		$(".list").css("height",page.height - $(".n-dttitle").outerHeight()-$(".colorinfo").outerHeight()-8);
	}else if($(".selchartlist").length>0){
		$(".list").css("height", page.height - $(".n-dttitle").outerHeight()-$(".selchartlist").outerHeight()-8);
	}else if($(".aqilist").length>0){
		var noticeheight=$(".table-notice ul").outerHeight()+57;
		$(".aqilist").css("height", page.height - $(".n-dttitle").outerHeight()-8);
		$("#table").height($(".aqilist").outerHeight()-noticeheight-45);
		$("#table1_tbodyDiv").height($("#table").height()-45);
	}else if($(".acquisitionlist").length>0){
		var noticeheight=$(".table-notice").outerHeight()+17;
		$(".acquisitionlist").css("height", page.height - $(".n-dttitle").outerHeight()-8);
		$("#table").height($(".acquisitionlist").outerHeight()-noticeheight-45);
		$("#table1_tbodyDiv").height($("#table").height()-45);
	}else if($(".selauditlist").length>0){
		$("#auditlist").css("height",page.height-$(".selauditlist").outerHeight()-5);
		$("#unauditlist").css("height",page.height-$(".selauditlist").outerHeight()-5);
		$(".list").css("height", $("#auditlist").outerHeight() - $(".n-dttitle").outerHeight()-5-4);
	}else if($("#svgFram").length>0){
		if($(".tab-drop").hasClass("tab-drop-down")){
			$(".diagram").css("height",(page.height-25)*0.8);
			$(".list").css("height",(page.height-25)*0.2);
			$(".equiplist").css("height",(page.height-25)*0.2);
			//$(".listchart").css("height",(page.height-25)*0.2);
			$(".listchart").css("height",$("#chartdata").outerHeight()+20);
		}else{
			$(".diagram").css("height",$(".n-right").height()-30);
    		$(".showdatalist").hide();
		}		
	}else if($("#titleDiv").length>0){
		$(".list").css("height",page.height - $(".n-dttitle").outerHeight()-$("#titleDiv").outerHeight()-$("#legendDiv").outerHeight()-8);
	}else{
		if($(".n-dttitle").length==0){
			$(".list").css("height",page.height);
		}else{
			$(".list").css("height",page.height - $(".n-dttitle").outerHeight()-chartHeight-refurbishHeight-8);
		}		
	}
	
	if($(".dirty-datalist").length>0){
		$(".tab-content .t-tbody").css("height",$(".list").outerHeight()-$(".box-title").outerHeight()-$(".thead-box").outerHeight()-15);
	}
	if($(".instrument").length>0){	
		$(".n-right-content").css("height",$(".n-right").height());
		$(".Bp").css("height",$(".n-right").height()*0.3);
		$(".instrument").css("height",$(".Clock-dial").outerHeight()+$(".Thtr").outerHeight());
		
		$(".table-alarm").css("height",($(".right-content").height()-130)*0.50);
		$(".air-changPic").css("height",($(".right-content").height()-130)*0.50);
		$(".changPic").css("height",$(".air-changPic").height()-40);
		$(".ctrlist").css("height",$(".table-alarm").height());
	}
	
	if($(".chartlist").length>0){
   	 	$(".chartlist").height($(".list").height()+15); 
	}
	
	 if($(".factor").length>0){
		 $(".box-zsgc").css("height","auto");
			$(".factor").css("width",$(".n-dttitle").width()-20); 
			$(".sl-e-more").html("展开<i></i>");
			$(".sl-e-more").removeClass("opened");
			if($(".box-zsgc").height()>36){
				$(".box-zsgc").css("height","36px");
				$(".sl-ext").show();
			}else{
				$(".sl-ext").hide();
			}
	 }
	 
	 if($("#pagination").length>0&&$("#reportDiv").length>0){
		var width=$("#pagination").width();
		var margin_left=$("#pagination").css("margin-left");
		$("#reportDiv").find("table").css("width",width).css("margin-left",margin_left);
	 }
	 
	 if($(".table-top-bg").length>0){
		 var right=$(".n-right").width()-32;
			$("#top").width(right-76);
			$("#bottom").width(right-76);
			$("#table").width(right);
			$("#center").width(right-27);
	 }
}

function getTreePageSize(){
	var width = document.documentElement.clientWidth;
	if(width===0){
		width = document.body.clientWidth;
	}
	if (width < 1024){
		width = 1024;
	}
	
	var height = document.documentElement.clientHeight;
	if(height===0){
		height = document.body.clientHeight;
	}
	if (height < 500){
		height = 500;
	}
	
	var treeWidth = 0;	
	var contentWidth = document.documentElement.clientWidth;
	if(contentWidth===0){
		contentWidth = document.body.clientWidth;
	}
	if (showTree){
		treeWidth = contentWidth * 0.2;
		if (treeWidth > 260){
			treeWidth = 260;
		}
		if (treeWidth < 200){
			treeWidth = 200;
		}
		contentWidth = width - treeWidth ;
	}
	
	return { width : width, height: height, treeWidth : treeWidth, contentWidth : contentWidth };
}